import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { MsgTipModule } from "../../../modules/MsgTipModule";
import { LayerManager } from "../manager/LayerManager";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { MsgTipInfo } from "../model/MsgTipInfo";
import { IMsgTipModule } from "../../../modules/interfaces/IMsgTipModule";
//class MsgTipControl
    
    export  class MsgTipControl extends Controller
    {
       

        protected /* override */ initView(): IView
        {
            if (this._msgTipModule == null) 
            {
                this._msgTipModule = new MsgTipModule();
                this._msgTipModule.layer = LayerManager.msgTipLayer;
            }
            return this._msgTipModule;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.MsgTipDateChange, this.msgTipDataChange);
            Dispatcher.addEventListener(EventName.MsgTipWindowHide, this.onMsgTipWindowHideHandler);
            return;
        }

        /* internal  */msgTipDataChange(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=arg1.data;
            if (_view == null) 
            {
                this.initView();
            }
            if (typeof loc1 === "msgtipinfo") 
            {
                loc2 = loc1 as MsgTipInfo;
            }
            if (this._msgTipModule.isHide || loc1 is MsgTipInfo && loc2.isAllowUpdate) 
            {
                if (typeof loc1 === "string") 
                {
                    loc3 = [loc1];
                    this._msgTipModule.isClick = 0;
                    this._msgTipModule.notTipEvent = "";
                    this._msgTipModule.isAutoHide = true;
                    this._msgTipModule.setContentTxt(loc3);
                }
                else if (typeof loc1 === "msgtipinfo") 
                {
                    this._msgTipModule.isClick = loc2.isClick;
                    this._msgTipModule.notTipEvent = loc2.notTipEvent;
                    this._msgTipModule.isAutoHide = loc2.isAutoHide;
                    if (loc2.type != 0) 
                    {
                        this._msgTipModule.addDisplayObject(loc2.displayObject);
                    }
                    else 
                    {
                        this._msgTipModule.isMultiLink = loc2.isMultiLink;
                        this._msgTipModule.setContentTxt(loc2.contentArr, loc2.clickEventArr, loc2.colorArr, loc2.itemColorArr, loc2.itemDataArr, loc2.isItemLinkArr, loc2.isItemNewLineArr);
                    }
                }
                this._msgTipModule.show();
            }
            return;
        }

        public stageResize(): void
        {
            if (this._msgTipModule != null) 
            {
                this._msgTipModule.stageResize();
            }
            return;
        }

        public onMsgTipWindowHideHandler(arg1: DataEvent): void
        {
            view.hide();
            return;
        }

        private /* var */_msgTipModule: IMsgTipModule;
    }
